﻿//-------------------------------------------------------------------------------------------
// <copyright file="App.xaml.cs" company="Russell Wilkins">
//     Copyright (c) Russell Wilkins 2014. All Rights Reserved.
// </copyright>
// <author>Russell Wilkins</author>
// <license href="license.txt">
//     The use of this software is governed by the Microsoft Public License
//     which is included with this distribution.
// </license>
//-------------------------------------------------------------------------------------------
namespace Ripple.TestClient
{
    using Views;
    using ViewModels;
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent, new RoutedEventHandler(SelectAllText));

            MainView mainView = new MainView();
            Settings.Default.InitalizeApplicationWindow(mainView);

            MainViewModel mainViewModel = new MainViewModel(new RippleContext());
            EventHandler handler = null;
            handler = delegate
            {
                mainViewModel.RequestClose -= handler;
                mainView.Close();
            };
            mainViewModel.RequestClose += handler;

            mainView.DataContext = mainViewModel;
            mainView.Show();
        }

        private void SelectAllText(object sender, RoutedEventArgs e)
        {
            var textBox = e.OriginalSource as TextBox;
            if (textBox != null)
            {
                textBox.SelectAll();
            }
        }
    }
}